$(function () {
    //Cotent
    //目标进度切换
    //左按钮
    var i = 0;
    var size = $(".targetProgress .target").length;
    $(".targetBox .prev").click(function () {
        if(i == 0){
            return
        }
        if(i > 0){
            $(this).siblings().removeClass("disable");
        }
        if(i == 1) {
            $(this).addClass("disable");
        }
        i --;
        move();
    });
    //右按钮
    $(".targetBox .next").click(function () {
        if(i == (size - 1)){
            return
        }
        if(i < (size - 1)){
            $(this).siblings().removeClass("disable");
        }
        if(i == (size - 2)){
            $(this).addClass("disable");
        }
        i ++;
        move();
    });
    //移动事件
    function move() {
        $(".targetProgress .target").stop().animate({ left: (-i) * 210,"transition":"all .3s" });
    }

    window.onscroll = function () {
        //导航条滚动事件
        var thisScrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
        var height1 = $(".SY-personal .pic").offset().top;
        var height2 = $(".SY-navigation .pushpin").offset().top;
        //第一阶段
        if(thisScrollTop > height1 - 50) {
            $(".SY-personal .S-userDetail").css("visibility","hidden");
            $(".SY-navigation .S-userDetail").fadeIn();
            //$(".SY-navigation.mark .support").css("visibility","visible");
            $(".SY-navigation ul").css("marginLeft","0");
        }else{
            $(".SY-personal .S-userDetail").css("visibility","visible");
            $(".SY-navigation .S-userDetail").fadeOut();
            //$(".SY-navigation.mark .support").css("visibility","hidden");
            $(".SY-navigation ul").css("marginLeft","168px");
        }
        //第二阶段
        if(thisScrollTop > height2 - 50) {
            $(".SY-navigation").addClass("touched");
        }else{
            $(".SY-navigation").removeClass("touched");
        }
        //第三阶段
        if(thisScrollTop > 550) {
            $(".SY-navigation.mark").css("visibility","hidden");
            $(".SY-navigation.pf").css("display","block");
        }else{
            $(".SY-navigation.mark").css("visibility","visible");
            $(".SY-navigation.pf").css("display","none");
        }

        //一键返回
        var btn = document.querySelector(".backToTop a");
        if (thisScrollTop >= 550) {
            btn.style.visibility = "visible";
            btn.style.position = "fixed";
            btn.style.bottom = "50px";
            btn.style.top = "auto";
            btn.style.transition = "all .5s";
        }else {
            btn.style.visibility = "hidden";
            btn.style.bottom = "50px";
            btn.style.top = "auto";
            btn.style.transition = "all .5s";
        }
        btn.onclick = function () {
            var pos = thisScrollTop;
            var speed = thisScrollTop / 50;

            var timer = setInterval(function () {
                pos -= speed;
                if (document.body.scrollTop) {
                    document.body.scrollTop = pos;
                } else {
                    document.documentElement.scrollTop = pos;
                }
                if (pos <= 0) {
                    clearInterval(timer)
                }
            }, 1);
        };

    };
    window.onscroll();

    //功能按钮显示隐藏
    $(".description .shares .ellipsis").click(function () {
        $(this).siblings(".unormal").slideToggle();
    });

    //评论列表展开与折叠
    $(".description .shares .comment").click(function () {
        $(this).parents(".description").siblings(".comments").slideToggle();
    });

    //新建评论
    $(".commentList .attitude .comment").click(function () {
        $(this).parents(".detail").find(".opinion").slideToggle();
    });

    //奖励回馈展开更多内容
    var spreadBtn = $(".S-rightBox .findMore .spread");
    spreadBtn.click(function(){
        if($(this).prev(".text").hasClass("fold")) {
            $(this).prev(".text").removeClass("fold");
            $(this).find(".word").html("收起");
            $(this).find(".fa").removeClass("fa-angle-double-down").addClass("fa-angle-double-up");
        }else{
            $(this).prev(".text").addClass("fold");
            $(this).find(".word").html("展开");
            $(this).find(".fa").removeClass("fa-angle-double-up").addClass("fa-angle-double-down");
        }

    });

    //S-centerBox 导航切换
    $(".S-centerBox .S-navBar li").click(function () {
       $(this).addClass("active").siblings().removeClass("active");
    });

    //点赞
    $(".showItem .description .thumbsUp").click(function () {
        $(this).toggleClass("active");
    });

    //评论区 点赞
    $(".showItem .comments .attitude .like").click(function () {
        $(this).find(".fa-heart").toggleClass("active");
    });

    //评论框获取光标 & 失去光标 事件
    $(".showItem .comments .myOpinion input").focus(function () {
        $(this).parent().addClass("focus");
    });
    $(".showItem .comments .myOpinion input").blur(function () {
        $(this).parent().removeClass("focus");
    });


    window._bd_share_config = {
        common : {
            bdText : '自定义分享内容',
            bdDesc : '自定义分享摘要',
            bdUrl : '自定义分享url地址',
            bdPic : '自定义分享图片'
        },
        share : [{
            "bdSize" : 32
        }]
    };
    with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];
});